package org.bendev.ildaplayer;

import android.os.Handler;

public class Timer {
	final long period;
	final Runnable onTimer;
	final Handler handler = new Handler();
	final Runnable run = new Runnable(){
		@Override
		public void run(){
			try{ onTimer.run(); }catch( Exception e ){}
			handler.postDelayed( this, period );
		}
	};

	public Timer( long period, Runnable onTimer ){
		this.period = period;
		this.onTimer = onTimer;
	}
	
	public void start(){
		handler.postDelayed( run, 0 );
	}
	
	public void stop(){
		handler.removeCallbacks( run );
	}
}
